﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using MahApps.Metro.Controls;
using MahApps.Metro.Controls.Dialogs;

namespace WpfBeyond
{
    /// <summary>
    /// WindowTaskDetail.xaml 的交互逻辑
    /// </summary>
    public partial class WindowTaskDetail : MetroWindow
    {

        TaskInfo taskinfo = null;

        public class device_item
        {
            private bool isCheck = false;
            private string serialNo = "";

            public bool IsCheck { get => isCheck; set => isCheck = value; }
            public string SerialNo { get => serialNo; set => serialNo = value; }
        }

        private List<device_item> dlist = new List<device_item>();

        public WindowTaskDetail(TaskInfo t)
        {
            InitializeComponent();

            taskinfo = t;

            //载入后，初始化参数
            lbl_ebmid.Content = taskinfo.Ebmid_str;
            lbl_bc_type.Content = taskinfo.Bc_type_str;
            lbl_event_level.Content = taskinfo.Event_level_str;
            lbl_content.Content = taskinfo.Content;
            lbl_rtp.Content = taskinfo.Rtp;
            lbl_source.Content = taskinfo.Source_str;

            grid_range.ItemsSource = taskinfo.Sel_dates;

            StringBuilder sb = new StringBuilder();
            //foreach (DateTimeRange dt in taskinfo.Sel_dates)
            //{
            //    sb.Append(dt.BeginTime.ToString(@"yyyy-MM-dd HH:mm:ss") + "--" 
            //        + dt.EndTime.ToString(@"yyyy-MM-dd HH:mm:ss") + "\r\n");
            //}
            //txt_begin_end_time.Text = sb.ToString();

            //sb.Remove(0, sb.Length);
            //foreach(string sn in taskinfo.Clients)
            //{
            //    sb.Append("SN:" + sn + "\r\n");
            //}
            //txt_clients.Text = sb.ToString();

            //list_client.ItemsSource = taskinfo.Clients;

            foreach (Device d in Devices.list)
            {
                device_item i = new device_item();
                i.SerialNo = d.serialNo;
                dlist.Add(i);
            }

            list_client.ItemsSource = dlist;

            foreach(string sn in taskinfo.Clients)
            {
                foreach(device_item i in dlist)
                {
                    if(i.SerialNo == sn)
                    {
                        i.IsCheck = true;
                    }
                }
            }

            grid_playlist.ItemsSource = taskinfo.Playlist;

            lbl_status.Content = taskinfo.Status_str;
            tbx.Text = taskinfo.Volume.ToString();

        }

        private void btn_add_device_Click(object sender, RoutedEventArgs e)
        {

        }

        private void SplitButton_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
        {

        }
                
    }
}
